package com.zyh.day02.value

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object MapPartitionsWithIndexTest {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setAppName("mp")
      .setMaster("local[*]")
    val sc = new SparkContext(conf)
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4, 5),2)
    val rdd2: RDD[Int] = rdd.mapPartitionsWithIndex((index,it) => {
      var list: List[Int] = List()
      for (item <- it) {
        list = list :+ (item * 10)
      }
      println("mapPartitions......."+index)
      list.iterator
    })
    rdd2.collect().foreach(println)

    sc.stop()
  }
}
